// pages/home/home.js
// const nav=['每日推荐','私人FM','歌单','排行榜','直播','数字专辑','歌房','游戏转区']
// var query = wx.createSelectorQuery();
Page({

  onShareAppMessage() {
    return {
      title: 'swiper',
      path: 'page/component/pages/swiper/swiper'
    }
  },
  /**
   * 页面的初始数据
   */
  data: {
    background: ['http://192.168.0.26:8081/img/swiper-1.jpg', 'http://192.168.0.26:8081/img/swiper-2.jpg', 'http://192.168.0.26:8081/img/swiper-3.jpg', 'http://192.168.0.26:8081/img/swiper-4.jpg', 'http://192.168.0.26:8081/img/swiper-5.jpg'],
    // nav:['每日推荐','私人FM','歌单','排行榜','直播','数字专辑','歌房','游戏转区'],
    show: true,
    nav: [{
      'title': '每日推荐',
      "name": "icon-rili"
    }, {
      'title': '私人FM',
      "name": "icon-luyinji"
    }, {
      'title': '歌单',
      "name": "icon-gedan"
    }, {
      'title': '排行榜',
      "name": "icon-paihangbang--"
    }, {
      'title': '直播',
      "name": "icon-zhibo"
    }, {
      'title': '数字专辑',
      "name": "icon-zhuanji"
    }, {
      'title': '歌房',
      "name": "icon-ufo"
    }, {
      'title': '游戏专区',
      "name": "icon-youxi"
    },],
    parentParam: [1, 2],
    list: [],
    songlist: [{
      "images": "http://192.168.0.26:8081/img/song-list-1.jpg",
      "title": "行在路上 寻找旅途的秘境",
      "time": "130万"
    }, {
      "images": "http://192.168.0.26:8081/img/song-list-2.jpg",
      "title": "网易云那些10至100w+评论的歌单按专辑排序",
      "time": "1953万"
    }, {
      "images": "http://192.168.0.26:8081/img/song-list-3.jpg",
      "title": "一起努力 做更好的自己",
      "time": "59.3亿"
    }, {
      "images": "http://192.168.0.26:8081/img/song-list-4.jpg",
      "title": "两个人互相惦念的见面才有意义",
      "time": "953万"
    }, {
      "images": "http://192.168.0.26:8081/img/song-list-5.jpg",
      "title": "神仙翻唱：超好听的女生翻唱集鸭",
      "time": "2072万"
    }],
    toView: 'green',
    recomsong: [{
      "child": [{
        "img": "http://192.168.0.26:8081/img/song-list-1.jpg",
        "title": "心墙（改编版）",
        "singer": "鸣小明"
      }, {
        "img": "http://192.168.0.26:8081/img/song-list-2.jpg",
        "title": "我应该去爱你（磁音女生版）",
        "singer": "澪恩Seiwen"
      }, {
        "img": "http://192.168.0.26:8081/img/song-list-3.jpg",
        "title": "How are you (Live)",
        "singer": "梁老师Tsong"
      }]
    }, {
      "child": [{
        "img": "http://192.168.0.26:8081/img/song-list-1.jpg",
        "title": "心墙（改编版）",
        "singer": "鸣小明"
      }, {
        "img": "http://192.168.0.26:8081/img/song-list-2.jpg",
        "title": "我应该去爱你（磁音女生版）",
        "singer": "澪恩Seiwen"
      }, {
        "img": "http://192.168.0.26:8081/img/song-list-3.jpg",
        "title": "How are you (Live)",
        "singer": "梁老师Tsong"
      }]
    }, {
      "child": [{
        "img": "http://192.168.0.26:8081/img/song-list-1.jpg",
        "title": "心墙（改编版）",
        "singer": "鸣小明"
      }, {
        "img": "http://192.168.0.26:8081/img/song-list-2.jpg",
        "title": "我应该去爱你（磁音女生版）",
        "singer": "澪恩Seiwen"
      }, {
        "img": "http://192.168.0.26:8081/img/song-list-3.jpg",
        "title": "How are you (Live)",
        "singer": "梁老师Tsong"
      }]
    },],
    username: "羊吃毛",
    left1: [{
      "icon": "icon-xinfengyoujian",
      "title": "我的信息"
    }, {
      "icon": "icon-yun",
      "title": "云贝中心"
    }, {
      "icon": "icon-deng-",
      "title": "创作者中心"
    },],
    left2: [{
      "icon": "icon-gouwuche",
      "title": "商城"
    }, {
      "icon": "icon-naozhong",
      "title": "音乐闹钟"
    }, {
      "icon": "icon-lingdang",
      "title": "口袋彩铃"
    },],
    left3: [{
      "icon": "icon-shezhi",
      "title": "设置"
    }, {
      "icon": "icon-fenxiang1",
      "title": "分享网易云音乐"
    }, {
      "icon": "icon-guanyu",
      "title": "关于"
    },],
    animationData: ""
  },
  upper(e) {
  },
  menushow(e) {
    this.animation.left(0).step();
    this.setData({
      animationData: this.animation.export()
    })
  },
  search() {
    wx.navigateTo({
      url: '../search/search',
    })
  },
  menuhide(e) {
    this.animation.left("-100%").step();
    this.setData({
      animationData: this.animation.export()
    })
  },
  todetails(e) {
    wx.navigateTo({
      url: `../details/details?id=${e.currentTarget.dataset.id}&songsheetCode=${e.currentTarget.dataset.songsheetcode}`,
    })
  },
  lower(e) {
    // console.log(e)
  },

  scroll(e) {
    // console.log(e)
  },

  scrollToTop() {
    this.setAction({
      scrollTop: 0
    })
  },
  skip(e) {
    if (e.currentTarget.dataset.index == "每日推荐") {

      wx.navigateTo({
        url: "../daily-recommendation/daily-recommendation"
      })
    } else if (e.currentTarget.dataset.index == "歌单") {
      wx.navigateTo({
        url: "../song-list/song-list"
      })
    } else if (e.currentTarget.dataset.index == "排行榜") {
      wx.navigateTo({
        url: "../ranking-list/ranking-list"
      })

    };
  },

  tap() {
    for (let i = 0; i < nav.length; ++i) {
      if (nav[i] === this.data.toView) {
        this.setData({
          toView: nav[i + 1],
          scrollTop: (i + 1) * 200
        })
        break
      }
    }
  },
  tosonglist() {
    wx.navigateTo({
      url: "../song-list/song-list"
    })
  },
  tapMove() {
    this.setData({
      scrollTop: this.data.scrollTop + 10
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (wx.getStorageSync('token') == 1) {
      this.setData({
        show: true
      })
    } else {
      this.setData({
        show: false
      })
    }
    wx.request({
      url: 'http://192.168.0.26:8081/songSheet/getManagementSongSheet',
      method: 'get',
      success: (res) => {
        if (res.data.data.imgUrl != "") {
          for (let i = 0; i < res.data.data.length; i++) {
            if (res.data.data[i].playNumber > 100000000) {
              res.data.data[i].playNumber = parseInt(res.data.data[i].playNumber / 10000000) + "亿"
            } else if (res.data.data[i].playNumber > 100000) {
              res.data.data[i].playNumber = parseInt(res.data.data[i].playNumber / 10000) + "万"
            }

            res.data.data[i].imgUrl =
              "http://192.168.0.26:8081" + res.data.data[i].imgUrl;
          }
        }
        res.data.data.sort(function () {
          return Math.random() > 0.5 ? -1 : 1;
        })
        this.setData({
          list: res.data.data.slice(0, 5)
        })

      },
    })
    this.animation = wx.createAnimation({
      duration: 200,
    })
    // 加载头像 
    wx.request({
      url: 'http://192.168.0.26:8081/user/getUserByCode',
      method: "post",
      data: {
        userCode: wx.getStorageSync('userCode')
      },
      success: (res) => {
        this.setData({
          parentParam: res.data.data
        })

      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () { },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (wx.getStorageSync('token') == 1) {
      this.setData({
        show: true
      })
    } else {
      this.setData({
        show: false
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    this.animation.left("-100%").step();
    this.setData({
      animationData: this.animation.export()
    })
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})